package com.sky.controller.subAccount;

import com.sky.constant.JwtClaimsConstant;
import com.sky.properties.JwtProperties;
import com.sky.result.Result;
import com.sky.utils.JwtUtil;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author : RemSynch
 * @Date: 2024/11/1 上午10:13
 * @Description:
 */
@RestController
@RequestMapping("/account")
@Api(tags = "账号信息相关接口")
public class accountManipulater {
    @Autowired
    private JwtProperties jwtProperties;

    @GetMapping("/checkLogin")
    @ApiOperation("校验登录情况")
    public Result checkLogin(HttpServletRequest request) {
        String token = request.getHeader(jwtProperties.getSubAccountsTokenName());
        Claims claims = JwtUtil.parseJWT(jwtProperties.getSubAccountsSecretKey(), token);
        if (claims != null) {
            return Result.success(claims);
        } else {
            return Result.error("登录验证失败");
        }
    }
}
